<?php

session_start();

include('page/sql_queries.php');
    
if( $_SESSION['logged']!=1 ){
	//user jest niezalogowany
	$user=$_POST['user'];
	
	if (isset($user)){
		$password=$_POST['password']; 
		
		if(check_password($user,$password)){ 
			$_SESSION['logged'] = 1;
		    $_SESSION['user'] = $_POST['user'];
		    
		    echo 'Witaj '.$_POST['user'].'. Klinij ';
			echo '<a href="../index.php?location=strona_glowna">tutaj</a>';
			exit;
		} else {
	  		echo 'Wrong password. Click <a href="../index.php">here</a>.';
	  	}
	}
	else{
		include('page/login_window.php');
	}
}
else{
	
	include('page/header.php');
	
	switch($_GET['location']){
	case 'pokaz_problem':
		include ('page/show_problem/show_problem.php');
		break;
	
        case 'dodaj_problem':
        	include ('page/add_problem/create_problem.php');
        	break;
        
        case 'edytuj_problem':
        	include ('page/edit_problem/edit_problem.php');
        	break;
        
        case 'dodaj_rozwiazanie':
        	include ('page/add_solution/add_new_solution.php');
        	break;
        	
        case 'pokaz_status':
        	include ('page/show_status/show_status.php');
        	break;
        	
        case 'dodaj_kategorie':
        	include ('page/add_category/create_category.php');
        	break;
        	
        case 'usun_kategorie':
        	include ('page/delete_category/delete_category.php');
        	break;
        
        case 'generuj_pdf':
        	include ('page/make_pdf/create_pdf.php');
        	break;

      	default:
      		include ('page/homepage/strona_glowna.php');
        	break;
	}
	include('page/footer.php');
	
}

?>
